package com.rock.code.province.tj.coll;

import com.alibaba.fastjson.JSONObject;
import com.rock.code.common.util.IMCUtil;
import com.rock.code.common.util.SpringContextUtil;
import com.rock.code.datacollconfig.coll.interfaces.CollDataItemInterface;
import com.rock.code.datacollconfig.h3c.dao.TbConfNetDao;
import com.rock.code.datacollconfig.h3c.domain.TB_CONF_NET_KPI;
import com.rock.code.datacollconfig.h3c.domain.TbConfNetIp;
import org.apache.log4j.Logger;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class IMCCollImpl implements CollDataItemInterface {

    private static Logger logger = Logger.getLogger("COLL");

    @Resource
    TbConfNetDao tbConfNetDao;

    @Override
    public void execute(String[] args) throws Exception {
        tbConfNetDao = (TbConfNetDao) SpringContextUtil.getBeanByClass(TbConfNetDao.class);

        logger.info("-----------------------Net start-------------------------");
        // 查询资源IP列表
        IMCUtil imcUtil = new IMCUtil();
        List<TbConfNetIp> ips = imcUtil.getIpsByParams();
        logger.info("ips的大小：" + ips.size());

        // 查询资源KPI列表
        Map<String, String> kpiParam = new HashMap();
        kpiParam.put("ENABLE", "1");
        List<TB_CONF_NET_KPI> kpis = tbConfNetDao.getAllNetKpiConf(kpiParam);
        logger.info("kpis的大小：" + kpis.size());

        // 采集
        try {
            IMCUtil.coll(ips, kpis);
        } catch (Throwable e) {
            e.printStackTrace();
            logger.error("采集失败");
        }
        logger.info("-----------------------Net end---------------------------");
    }

    public static void main(String[] args) {
        JSONObject res = IMCUtil.listAlarm("8346");
        System.out.println(res);
    }
}

